{include file="pageheader_erp.htm"}

{include file="erp_supplier_search.htm"}

{insert_scripts files="../js/jquery.1.3.2.js"}

<style type="text/css">
	.current_page_style
	{
		color:red;
		font-weight:bold;
	}
</style>


 <!-- start supplier list -->
 <div class="list-div" id="listDiv">
<table  cellpadding="3" cellspacing="1">
  <tr>
    <th width="5%">{$lang.erp_supplier_id}</th>
    <th width="5%">{$lang.erp_supplier_code}</th>
 	<th width="20%">{$lang.erp_supplier_name}</th>
	<th>{$lang.erp_supplier_address}</th>
	<th width="10%">{$lang.erp_supplier_contact}</th>
	<th width="10%">{$lang.erp_supplier_tel}</th>
	<th width="10%">{$lang.erp_supplier_fax}</th>
	
	<th width="10%">{$lang.erp_supplier_group_name}</th>
	
	<th>{$lang.erp_admin}</th>
	
	<th width="5%">{$lang.erp_is_valid}</th>
	<th width="8%">{$lang.erp_operation}</th>
  <tr>
  {foreach from=$supplier_info item=supplier}
  <tr id="tr_{$supplier.supplier_id}">
    <td align="center">{$supplier.supplier_id}</td>
	<td align="center"><span id="span_code_{$supplier.supplier_id}">{$supplier.code}</span><input type="text" size="5" maxlength="5" style="display:none;" id="input_code_{$supplier.supplier_id}" value="{$supplier.code}"></td>
	<td ><span id="span_name_{$supplier.supplier_id}">{$supplier.name}</span><input type="text" size="25"  style="display:none;" id="input_name_{$supplier.supplier_id}" value="{$supplier.name}"></td>
	<td ><span id="span_address_{$supplier.supplier_id}">{$supplier.address}</span><input type="text" size="25" style="display:none;" id="input_address_{$supplier.supplier_id}" value="{$supplier.address}"></td>
	<td ><span id="span_contact_{$supplier.supplier_id}">{$supplier.contact}</span><input type="text" size="12" style="display:none;" id="input_contact_{$supplier.supplier_id}" value="{$supplier.contact}"></td>
	<td ><span id="span_tel_{$supplier.supplier_id}">{$supplier.tel}</span><input type="text" size="12" style="display:none;" id="input_tel_{$supplier.supplier_id}" value="{$supplier.tel}"></td>
	<td ><span id="span_fax_{$supplier.supplier_id}">{$supplier.fax}</span><input type="text" size="12" style="display:none;" id="input_fax_{$supplier.supplier_id}" value="{$supplier.fax}"></td>
	
	<td >
		<span id="span_group_{$supplier.supplier_id}" style="cursor:pointer;">{$supplier.supplier_group_name}</span>
		{if $supplier_group}
			<select id="select_group_{$supplier.supplier_id}" style="display:none;">
				{foreach from=$supplier_group item=group}
					<option value="{$group.group_id}" {if $supplier.supplier_group_id eq $group.group_id}selected="selected"{/if}>{$group.group_name}</option>
				{/foreach}
			</select>
		{/if}
	</td>
	
	<td>
		<span style="cursor:pointer;"  id="span_admin_{$supplier.supplier_id}">{$supplier.admin_name}</span>
		{if $admins}
		<select id="select_admin_name_{$supplier.supplier_id}" style="display:none;">
			{foreach from=$admins item=admin}
				<option value='{$admin.user_id}' {if $supplier.admin_id eq $admin.user_id}selected='selected'{/if}>{$admin.user_name}</option>
			{/foreach}
		</select>
		{/if}
	</td>	
	
	<td align="center" ><span id="is_valid_{$supplier.supplier_id}" style="cursor:pointer; color:{if $supplier.is_valid eq 1}red;{else}black;{/if}">{if $supplier.is_valid eq 1}{$lang.erp_yes}{else}{$lang.erp_no}{/if}</span></td>
	<td align="center"  >
		<span id="edit_{$supplier.supplier_id}" style="cursor:pointer;">{$lang.erp_operation_edit}</span>
		<span id="delete_{$supplier.supplier_id}" style="cursor:pointer;">{$lang.erp_operation_delete}</span>
    </td>				
  </tr>
  {foreachelse}
  <tr><td class="no-records" colspan="11">{$lang.no_records}</td></tr>
  {/foreach}
   <tr><td colspan="11" align="right">{$page}</td></tr>   
</table>
</div>
<!-- end goods list -->

{literal}
<script language="JavaScript">
   $(document).ready(function(){
   	
		$("span[id^='delete_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='delete_']").mouseout(function(){
			$(this).css('color','black');
		});	
			
	
			
		$("span[id^='delete_']").click(function(){
			var $select_item=$(this);
			var supplier_id=$select_item.attr('id');
			supplier_id=supplier_id.substr(7,supplier_id.length-7);
			
			function deleteSupplierResponse(res)
			{
				if(res.error==0)
				{
					var tr_str="#tr_"+supplier_id;
					$(tr_str).hide();
				}
				else{
					alert(res.message);
				}
			}
			
			if(confirm('{$lang.erp_sure_to_delete}')){
				Ajax.call('erp_supplier.php?act=delete_supplier', 'supplier_id=' + supplier_id, deleteSupplierResponse, 'POST', 'JSON');
			}
			
		});

		$("span[id^='edit_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='edit_']").mouseout(function(){
			$(this).css('color','black');
		});	
	
		$("span[id^='edit_']").click(function(){
			var $select_item=$(this);
			var supplier_id=$select_item.attr('id');
			supplier_id=supplier_id.substr('edit_'.length,supplier_id.length-'edit_'.length);
			
			window.location='erp_supplier.php?act=edit_supplier&supplier_id='+supplier_id;
		});			
	
		$("span[id^='span_group_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='span_group_']").mouseout(function(){
			$(this).css('color','black');
		});	
		
		$("span[id^='span_group_']").click(function(){
			var supplier_id=$(this).attr('id');
			supplier_id=supplier_id.substr('span_group_'.length,supplier_id.length-'span_group_'.length);
			
			$(this).hide();
			$("#select_group_"+supplier_id).show();
		});	
	
		$("select[id^='select_group_']").change(function(){
			var supplier_id=$(this).attr('id');
			supplier_id=supplier_id.substr('select_group_'.length,supplier_id.length-'select_group_'.length);
			
			var supplier_group_id=$(this).attr('value');
			
			Ajax.call('erp_supplier.php?act=change_group', 'supplier_id=' + supplier_id +'&supplier_group_id='+supplier_group_id, changeSupplierGroupResponse, 'POST', 'JSON');
			
			function changeSupplierGroupResponse(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					window.location='{$url}';
				}			
			}
		});		
	
	
   		$("span[id^='is_valid_']").click(function(){
			var $this=$(this);
			var supplier_id=$this.attr('id');
			supplier_id=supplier_id.substr(9,supplier_id.length-9);
			
			function changeIsValidResponse(res)
			{
				if(res.error==0 && res.is_valid==1)
				{
					$this.css('color','red');
					$this.text('{$lang.erp_yes}');
				}
				else if(res.error==0 && res.is_valid===0)
				{
					$this.css('color','black');
					$this.text('{$lang.erp_no}');
				}
				else{
					alert(res.message);
				}
			}
			
			Ajax.call('erp_supplier.php?act=change_is_valid', 'supplier_id=' + supplier_id, changeIsValidResponse, 'POST', 'JSON');
		});
		
			
		//显示该供应商下的产品（修改供应商名称)
		$("span[id^='span_name_']").attr('style','cursor:pointer;');
		$("span[id^='span_name_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_name_']").mouseout(function(){
			$(this).css('color','black');
		});		
				
		$("span[id^='span_name_']").click(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(10,supplier_id.length-10);
			
			window.location='goods.php?act=list&suppliers_id='+supplier_id;

		});

		
		$("input[id^='input_name_']").blur(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(11,supplier_id.length-11);
			
			var $span_name=$("#span_name_"+supplier_id);
			var new_name=$(this).attr('value');
			
			var $input_name=$(this);

			function changeSupplierNameResponse(result)
			{
				if(result.error!=0)
				{
					alert(result.message);
					$input_name.focus();
				}
				else{
					$input_name.hide();
					$span_name.text(new_name);
					$span_name.show();					
				}
				}
			Ajax.call('erp_supplier.php?act=change_name', 'supplier_id=' + supplier_id+"&new_name="+new_name, changeSupplierNameResponse, 'POST', 'JSON');
		
		});	
		
		//修改供应商地址
		$("span[id^='span_address_']").attr('style','cursor:pointer;');
		$("span[id^='span_address_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_address_']").mouseout(function(){
			$(this).css('color','black');
		});		
				
		$("span[id^='span_address_']").click(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(13,supplier_id.length-13);
			
			var $input_address=$("#input_address_"+supplier_id);
			$(this).hide();
			$input_address.show();
			$input_address.focus();
		});
		
		$("input[id^='input_address_']").blur(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(14,supplier_id.length-14);
			
			var $span_address=$("#span_address_"+supplier_id);
			var new_address=$(this).attr('value');
			
			var $input_address=$(this);

			function changeSupplierAddressResponse(result)
			{

				if(result.error==1)
				{
					alert(result.message);
					$input_address.focus();
				}
				else if(result.error==2)
				{
					$span_address.text(result.address)
					$input_address.attr('value',result.address);
					$input_address.hide();
					$span_address.show();
				}
				else{
					$input_address.hide();
					$span_address.text(new_address);
					$span_address.show();					
				}
			}
			Ajax.call('erp_supplier.php?act=change_address', 'supplier_id=' + supplier_id+"&new_address="+new_address, changeSupplierAddressResponse, 'POST', 'JSON');
		
		});	
				
		//修改供应商联系人
		$("span[id^='span_contact_']").attr('style','cursor:pointer;');
		$("span[id^='span_contact_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_contact_']").mouseout(function(){
			$(this).css('color','black');
		});		
				
		$("span[id^='span_contact_']").click(function(){
			var id_t=$(this).attr('id');
			var supplier_id=id_t.substr(13,id_t.length-13);
			
			var obj_s="#input_contact_"+supplier_id;
			var $input_contact=$(obj_s);
			$(this).hide();
			$input_contact.show();
			$input_contact.focus();
		});
		
		$("input[id^='input_contact_']").blur(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(14,supplier_id.length-14);
			
			var $span_contact=$("#span_contact_"+supplier_id);
			var new_contact=$(this).attr('value');
			
			var $input_contact=$(this);

			function changeSupplierContactResponse(result)
			{

				if(result.error==1)
				{
					alert(result.message);
					$input_contact.focus();
				}
				else if(result.error==2)
				{
					$span_contact.text(result.contact)
					$input_contact.attr('value',result.contact);
					$input_contact.hide();
					$span_contact.show();					
				}
				else{
					$input_contact.hide();
					$span_contact.text(new_contact);
					$span_contact.show();					
				}
				}
			Ajax.call('erp_supplier.php?act=change_contact', 'supplier_id=' + supplier_id+"&new_contact="+new_contact, changeSupplierContactResponse, 'POST', 'JSON');
		
		});	
		
		//修改供应商电话
		$("span[id^='span_tel_']").attr('style','cursor:pointer;');
		$("span[id^='span_tel_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_tel_']").mouseout(function(){
			$(this).css('color','black');
		});		
				
		$("span[id^='span_tel_']").click(function(){
			var id_t=$(this).attr('id');
			var supplier_id=id_t.substr(9,id_t.length-9);
			
			var obj_s="#input_tel_"+supplier_id;
			var $input_tel=$(obj_s);
			$(this).hide();
			$input_tel.show();
			$input_tel.focus();
		});
		
		$("input[id^='input_tel_']").blur(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(10,supplier_id.length-10);

			var $span_tel=$("#span_tel_"+supplier_id);
			var new_tel=$(this).attr('value');
			
			var $input_tel=$(this);

			function changesupplierTelResponse(result)
			{

				if(result.error==1)
				{
					alert(result.message);
					$input_tel.focus();
				}
				else if(result.error==2)
				{
					$span_tel.text(result.tel)
					$input_tel.attr('value',result.tel);
					$input_tel.hide();
					$span_tel.show();					
				}
				else{
					$input_tel.hide();
					$span_tel.text(new_tel);
					$span_tel.show();					
				}
				}
			Ajax.call('erp_supplier.php?act=change_tel', 'supplier_id=' + supplier_id+"&new_tel="+new_tel, changesupplierTelResponse, 'POST', 'JSON');
		
		});
		
		//修改供应商传真
		$("span[id^='span_fax_']").attr('style','cursor:pointer;');
		$("span[id^='span_fax_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_fax_']").mouseout(function(){
			$(this).css('color','black');
		});		
				
		$("span[id^='span_fax_']").click(function(){
			var supplier_id=$(this).attr('id');
			var supplier_id=supplier_id.substr(9,supplier_id.length-9);
			
			var $input_fax=$("#input_fax_"+supplier_id);
			$(this).hide();
			$input_fax.show();
			$input_fax.focus();
		});
		
		$("input[id^='input_fax_']").blur(function(){
			var id_t=$(this).attr('id');
			var supplier_id=id_t.substr(10,id_t.length-10);
			
			var obj_s="#span_fax_"+supplier_id;
			var $span_fax=$(obj_s);
			var new_fax=$(this).attr('value');
			
			var $input_fax=$(this);

			function changesupplierFaxResponse(result)
			{

				if(result.error==1)
				{
					alert(result.message);
					$input_fax.focus();
				}
				else if(result.error==2)
				{
					$span_fax.text(result.fax)
					$input_fax.attr('value',result.fax);
					$input_fax.hide();
					$span_fax.show();					
				}
				else{
					$input_fax.hide();
					$span_fax.text(new_fax);
					$span_fax.show();					
				}
				}
			Ajax.call('erp_supplier.php?act=change_fax', 'supplier_id=' + supplier_id+"&new_fax="+new_fax, changesupplierFaxResponse, 'POST', 'JSON');
		
		});
	
		$("span[id^='span_admin_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='span_admin_']").mouseout(function(){
			$(this).css('color','black');
		});	
	
		$("span[id^='span_admin_']").click(function(){
			var group_id=$(this).attr('id');
			group_id=group_id.substr('span_admin_'.length,group_id.length-'span_admin_'.length);	
			$(this).hide();
			$("#select_admin_name_"+group_id).show();
		});
		
		$("select[id^='select_admin_name_']").change(function(){
			var supplier_id=$(this).attr('id');
			supplier_id=supplier_id.substr('select_admin_name_'.length,supplier_id.length-'select_admin_name_'.length);	
			
			var admin_id=$(this).attr('value');
			
			Ajax.call('erp_supplier.php?act=change_admin', 'supplier_id=' + supplier_id+ '&admin_id=' + admin_id, changeSupplierAdminResponse, 'POST', 'JSON');
		
			function changeSupplierAdminResponse(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					window.location='{$url}';
				}
			}
		});	
   });   
</script>
{/literal}
{include file="pagefooter.htm"}

